package com.tarena.practice.manage.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.tarena.practice.manage.pojo.Comment;
import com.tarena.practice.manage.pojo.Topic;
import com.tarena.practice.manage.service.CommentService;
import com.tarena.practice.manage.vo.PageUtils;

@Controller
@RequestMapping("comment/")
public class CommentController {
	
	@Autowired
	private CommentService commentService;
	
	/**
	 * 根据题目id分页查询相关评论， 
	 * @param pageNum
	 * @param pageSize
	 * @param topicId
	 * @return
	 */
	@RequestMapping(value="query/page", method={RequestMethod.POST, RequestMethod.GET})
	@ResponseBody
	public PageUtils<Comment> comments(@RequestParam(value="pageNum",defaultValue="1", required=false) Integer pageNum, @RequestParam(value="pageSize",defaultValue="20", required=false) Integer pageSize, @RequestParam(value="topicId",required=false, defaultValue="1" ) Integer topicId) {
		PageUtils<Comment> result = commentService.queryCommentsByTopicId(pageNum, pageSize, topicId);
		return result;
	}
}
